﻿//-----------------------------------------------------------------------
// <copyright file="ServerCommunicationManager.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings
using System;
using System.Collections.Generic;
using System.ServiceModel;
using FastNET.CleanAct.Client.ManagerEngine.ServiceHosts;
using FastNET.CleanAct.Common.Contracts.ServiceContracts;
using FastNET.CleanAct.Common.EngineModel.Managers;
using FastNET.CleanAct.Common.EngineModel.Managers.Interface;

#endregion

namespace FastNET.CleanAct.Client.ManagerEngine.Managers
{
    /// <summary>
    /// CommunicationManager class for the Control Engine
    /// </summary>
    internal class ServerCommunicationManager : CommunicationManagerBase
    {
        private readonly ProcessingHost _processingHost;
        private readonly IServerDataManager _dataManager;

        public ServerCommunicationManager(IServerDataManager dataManager)
        {
            _dataManager = dataManager;
            _processingHost = new ProcessingHost(_dataManager);
        }

        #region Instance Creation

        /// <summary>
        /// Called to allow the inherited class to initialize the instance of the factory for the requested channel type
        /// </summary>
        /// <param name="channelType">Type of the channel the factory should be for</param>
        /// <returns>ChannelFactory of IChannel that was created</returns>
        protected override ChannelFactory CreateFactoryInstance(Type channelType)
        {
            return null;
        }

        /// <summary>
        /// Called to allow the inherited class to initialize the instance of the ServiceHost for the requested host type
        /// </summary>
        /// <param name="hostType">Type of the host should be for</param>
        /// <returns>ServiceHost that was created</returns>
        protected override ServiceHost CreateHostInstance(Type hostType)
        {
            if (hostType == typeof(IProcessingServerContract) && _processingHost != null)
            {
                return new ServiceHost(_processingHost);
            }

            return null;
        }

        /// <summary>
        /// Gets a list of all channel types this communication manager is managing
        /// </summary>
        /// <returns>List of Type for all supported channels</returns>
        protected override List<Type> GetChannelTypes()
        {
            return new List<Type>();
        }

        /// <summary>
        /// Gets a list of all host types this communication manager is managing
        /// </summary>
        /// <returns>List of Type for all supported host</returns>
        protected override List<Type> GetHostTypes()
        {
            return new List<Type> { typeof(IProcessingServerContract) };
        }

        #endregion

    }
}
